package com.example.java_chatroom.controller;

import com.example.java_chatroom.model.Message;
import com.example.java_chatroom.service.MessageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    private MessageService messageService;

    @GetMapping("/message")
    public Object getMessage(int sessionId){
        List<Message> messages=messageService.getMessageBySessionId(sessionId);
        //针对查询结果，进行你只操作，上面需要的是按时间升序排列的消息，此处得到的是降序排列
        Collections.reverse(messages);
        return  messages;
    }


}
